<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件处理</title>
  <style>

  </style>
</head>

<body>
<!-- 创建test -->
<div id="test"></div>
<!-- 引入核心库 -->
<script src="../js/react.development.js"></script>
<!-- 引入react操作DOM支持库 -->
<script src="../js/react-dom.development.js"></script>
<!-- 引入babel 用于将jsx转为js -->
<script src="../js/babel.min.js"></script>
<!-- 引入prop-types 用于对组件标签属性进行限制 -->
<script src="../js/prop-types.js"></script>
<script type="text/babel">  // 此处引入一定要写babel
class Demo extends React.Component {
  /**
   * React.createRef()  调用后返回一个容器,该容器可以存储被ref所标识的节点,该容易为专人专用
   * */
  /**
   * 事件委托机制
   * */
  myRef = React.createRef();
  render() {
    return (
      <div>
        <label>
          <input ref={this.myRef} type="text" placeholder="点击按钮提示数据"/>
        </label>
        <button onClick={this.showData}>点我提示左侧数据</button>
      </div>
    )
  }

  showData = () => {
    alert(this.myRef.current.value)
  }
}

ReactDOM.render(<Demo/>, document.getElementById("test"))
</script>
</body>

</html>